! 6532 test for Gottlieb System 80 FEB 17, 2002 PIA only
! 
! REG1 = TEST NUMBER/DELAY COUNTER
! REG2 = BIT NUMBER/PIN NUMBER
! REG3 = BIT NUMBER
! REG4 =
! REG5 = COUNTER
! REG6 = SIGNATURE NUMBER
! REG7 = QUESTION ASKED OF USER
! REG8 = DIP SWITCH NUMBER
! REG9 = IC NUMBER 4, 5, OR 6

PROGRAM 1          !basic tests

SYNC FREE-RUN 
DPY-BUS TEST
EX PROGRAM 12
BUS TEST
DPY-+# OK!
EX PROGRAM 12
DPY-RAM TEST
RAM LONG 0 - 17F
DPY-+# RAM OK!
EX PROGRAM 12
DPY-U2 ROM TEST
ROM @ 2000-2FFF SIG C6AE
DPY-+# U2 OK!
EX PROGRAM 12
DPY-U3 ROM TEST
ROM @ 3000-3FFF SIG 0F6E
DPY-+# U3 OK!
EX PROGRAM 12

PROGRAM 2                !dip switch tests DIP SW. OFF WORKS!!!!
       
      REG8 = F
        DPY-TURN OFF ALL DIP SWITCHES       !check dip switches first, if this is sick nothing works!
        DPY-+ CONT#
        STOP
      
       EX PROGRAM 12
       
        WRITE @ 0303 = FF               !U6 PBx to outputs
        WRITE @ 0301 = FF               !U6 PAx to outputs
        WRITE @ 0302 = F0               !U6 PBx all high (no switch enable)
        WRITE @ 0283 = FF               !U5 PBx to outputs
        WRITE @ 0281 = 7F               !U5 PA7 to input others out
        WRITE @ 0282 = 00               !U5 PBx disable switch enable
        WRITE @ 0203 = 00               !U4 PBx to inputs
        WRITE @ 0201 = FF               !U4 PAx to outputs
        REGF = 0200                     !default switch read
        READ @ REGF
        IF REGE > 00 GOTO 3

        IF REG8 = F GOTO 2

1: LABEL 1
        DPY-TURN OFF DIP SWITCH BANK $8       !check dip switches first, if this is sick nothing works!
        DPY-+ CONT#
        STOP
        
2: LABEL 2        
        WRITE @ 0282 = 80                  !turn on PB7
        WRITE @ 0302 = 0F                  !enable DS0 (low)
        READ @ 0200                        !see if dip bank one are all open
        REG8 = 1                           !set dip switch number flag
        IF REGE > 00 GOTO 1                !one of dip switch 1 is on.
        WRITE @ 0302 = 1F
        READ @ 0200
        REG8 = 2
        IF REGE > 00 GOTO 1
        WRITE @ 0302 = 2F
        READ @ 0200
        REG8 = 3
        IF REGE > 00 GOTO 1
        WRITE @ 0302 = 3F
        READ @ 0200
        REG8 = 4
        IF REGE > 00 GOTO 1
        IF REGE = 00 GOTO 4

3: LABEL 3
DPY-SOMETHING IS WRONG WITH U4###
STOP

4: LABEL 4
        DPY-TURN ALL DIP SWITCHES ON
        DPY-+ CONT#
        STOP
        READ @ 0200
        IF REGE = FF GOTO 5
        REG8 = 1
        IF REGE >=0 GOTO F

5: LABEL 5
        WRITE @ 0302 = 1F                                     !enable DS1 (low)
        READ @ 0200
        IF REGE = FF GOTO 6
        REG8 = 2
        IF REGE >=0 GOTO F

6: LABEL 6
        WRITE @ 0302 = 2F                                     !enable DS2 (low)
        READ @ 0200
        IF REGE = FF GOTO 7
        REG8 = 3
        IF REGE >= 0 GOTO F

7: LABEL 7
        WRITE @ 0302 = 3F                                     !enable DS3 (low)
        READ @ 0200
        IF REGE = FF GOTO 8
        REG8 = 4
        IF REGE >= 0 GOTO F

8: LABEL 8
        DPY-DIP SWITCH TEST PASSES...
        EX PROGRAM 12
        EX PROGRAM 16

F: LABEL F
        DPY-DIP SW. BANK $8 NUMBER $E FAILS#
        STOP
        DPY-TRY AGAIN? YES/NO #?7
        IF REG 7 = 1 GOTO 4

        EX PROGRAM 16

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !DELAY ROUTINE

PROGRAM 12
REG1=40
0:
DEC REG1
IF REG1 >0 GOTO 0

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

PROGRAM 16                                      !PIA test

   DPY-PIA TEST <U$9>#
   SYNC ADDRESS
   EXECUTE PROGRAM 12               !delay
   DPY-+-CONT#
   STOP
   REG1 = 0                         !test number clear
   REG9 = 5                         !1st pia to test

1: LABEL 1 
   INC REG1                         !increment test number
   REG3 = 0                         !clear bit number
   IF REG1 = 6 GOTO F               !Finished!
   IF REG1 = 5 GOTO 7               !Test CBX pins (6821 would be same!)
   IF REG1 = 4 GOTO 4               !Test Port B output (old) 
   IF REG1 = 3 GOTO F               !Test Port A input we'll finish for now...
   IF REG1 = 2 GOTO 2               !Test Port B output else Test Port A output

   DPY-#TEST PORT A OUT/INPUT       !PA7 is input, rest are outs
   EXECUTE PROGRAM 12               !delay
   DPY-TESTER PULSE HIGH, LOW OUT-
   DPY-+CONT#
   STOP
   WRITE @ 0281 = 0                     !set REGF to 0281 output register
   WRITE @ REGF = 7F             !pia port a to input Part of
!   WRITE @ REGF INC = 4                                    Test 1
   REG2 = 8                          !1st pia pin number
   REG6 = A00                        !expected signature
   WRITE @ REGF DEC = 1              !set port a r/w address
!   REGF = 0280                      !pia port a address
   GOTO 5

2: LABEL 2
   DPY-#TEST PORT B OUTPUT
   EXECUTE PROGRAM 12
   WRITE @ 0283 = 0
   WRITE @ REGF = FF             !pia port b to output  Part of
!!   WRITE @ REGF = 4              !                       Test 2
   REG2 = 24                         !enter 1st pia pin number
   REG6 = A00                        !expected signature
   REGF = 0282                       !pia port b address
   GOTO 5

3: LABEL 3
   DPY-TEST PORT A INPUT#
   EXECUTE PROGRAM 12
   WRITE @ 0281 = 0                 !PIA port a to input    Part of
   WRITE @ REGF DEC = 0             !                       Test 3
   WRITE @ REGF INC = 4
   DPY-TESTER PULSE HIGH, LOW IN-
   DPY-+CONT#
   STOP
   REG2 = 2                          !1st pia pin number
   REG6 = 1                          !expected signature
   REGF = 100C0                      !port a address
   GOTO 5

4: LABEL 4
!DPY-TEST PORT B OUTPUT#
!EXECUTE PROGRAM 12
!WRITE @ 0803 = 00                                !pia port b to input! Part of Test 4
!WRITE @ REGF DEC = 0                            
!WRITE @ REGF INC = 4
!REG2 = 10                                       !1st pia pin number
!REG6 = 1                                        !expected signature
!REGF = 0803                                     !port b address

5: LABEL 5
DPY-PR0BE U$9 PIN $2                             !does oper wish to probe current pia pin?
DPY-+, YES/NO #?7
IF REG7 = 0 GOTO D                              !no - increment pin and bit number
READ PROBE                                      !yes - read probe
IF REG1 = 5 GOTO 8                              !if test 4 complete, check cb2 line
IF REG1 > 2 GOTO 6                              !if test 2 complete, continue with test 3, or 4
WRITE @ REGF = 0                                !sets pia port to 0
DTOG @ REGF = FF BIT REG3                       !toggle the bit no. in reg. 3 (Part of Test 1 and 2)
DTOG @ REGF = REGE BIT REGD                     !repeat toggle using defaul t reg.
WRITE @ REGF = 0                                !pia to zero
READ PROBE                                      !gather signature
IF REG0 AND FFFF00 = REG6 GOTO C                !mask off all but sig and check against reg. 6
GOTO E

6: LABEL 6
READ @ REGF                                     !read pulse at pia portPart
REG8 = REGE                                     !save dataof
READ @ REGF                                     !read pulse at pia portTest
IF REG8 AND REG6 = REGE AND REG6 GOTO E         !if pulse present 3 and 4 at each read, error
SHL REG6                                        !move the test bit to next position for next pia pin check
GOTO C

7: LABEL 7
!DPY-#CB2 TEST
!EXECUTE PROGRAM 12
!DPY-TESTER PULSE HIGH, LOW OUT­
!DPY-+CONT#
!STOP
!REG2 = 19                                       !cb2 pin no.
!REG3 = 7                                        !full count in bit counter
!REG6 = 2                                        !expected event count
!GOTO 5

8: LABEL 8
WRITE @ 100C3 = 38
WRITE @ REGF = 30                               !stimulate cb2 line
WRITE @ REGF = 38
WRITE @ REGF = 30
READ PROBE                                      !gather event count
IF REG0 AND 7F = REG6 GOTO C                    !verity event count - o.k. goto a
GOTO E                                          !not correct count - goto e

9: LABEL 9
DPY-
DEC REG2 
DEC REG2
DEC REG2
DEC REG2
DEC REG2
DEC REG2

C: LABEL C                                      !sig o.k.
DPY-+, GOOD
EXECUTE PROGRAM 12                              !delay

D: LABEL D
DEC REG2                                        !increment pin
IF REG2 = 20 GOTO 9                !skip pin 20
INC REG3                                        !increment bit
IF REG3 = 8 GOTO 1
GOTO 5

E: LABEL E                                      !sig. failure
DPY-'U$9 PIN $2 BIT $3 FAILURE
DPY-+ LOOP'?5                                   !repeat test
IF REG5 = 1 GOTO 5                              !yes
DPY-TEST FAIL#
STOP

F: LABEL F
DPY-PIA TEST PASSED#
